<template>
  <div>
        <el-popover placement="bottom-start" width="1000" style="margin-right:10px;" trigger="click">
          <el-form :inline="true" :model="search">
              <el-form-item label="任务单号" >
                  <el-input v-model="search.taskNo" clearable></el-input>
              </el-form-item> 
              <el-form-item label="任务流水号单号" >
                  <el-input v-model="search.taskSerialNo" clearable></el-input>
              </el-form-item> 
              <el-form-item label="生产令号" >
                  <el-input v-model="search.makeNo" clearable></el-input>
              </el-form-item> 
              <el-form-item label="图纸编号" >
                  <el-input v-model="search.drawCode" clearable></el-input>
              </el-form-item> 
              <el-form-item label="29所编码" >
                  <el-input v-model="search.code29" clearable></el-input>
              </el-form-item>
<!-- 
              <el-form-item label="是否是毛坯外协" >
                  <el-select v-model="search.isMp" clearable>
                      <el-option label="否" value="0"></el-option>
                      <el-option label="是" value="1"></el-option>
                  </el-select>
              </el-form-item> -->
                         
              <el-button type="primary" @click="searchBtn">确认</el-button>
              <el-button type="primary" @click="restSearchBtn">重置</el-button>
          </el-form>
          <el-button slot="reference" type="primary" icon="el-icon-search">查询</el-button>
          <el-button slot="reference" type="primary" @click="cpkOut" >出库</el-button>
        </el-popover>
            <el-table :data="tableList" stripe border class="user-table"   @selection-change="handleSelectionChange"   style="width: 100%;">
                <el-table-column type="selection" sortable min-width="100"></el-table-column>
                <el-table-column prop="taskNo" label="任务单号" sortable min-width="100"></el-table-column>
                <el-table-column prop="code29" label="29所编号" sortable min-width="80"></el-table-column>
                <el-table-column prop="taskSerialNo" label="任务流水号" sortable min-width="80"></el-table-column>
                <el-table-column prop="makeNo" label="生产令号" sortable min-width="80"></el-table-column>
                <el-table-column prop="drawCode" label="图纸编号" sortable min-width="80"></el-table-column>
                <el-table-column prop="drawName" label="图纸名称" sortable min-width="80"></el-table-column>
                <el-table-column prop="wbPlanFinsihDate" label="外包计划完成时间" sortable min-width="80"></el-table-column>
                <el-table-column prop="productFinishTime" label="入库时间" sortable min-width="80"></el-table-column>
                <el-table-column prop="nums" label="件数" sortable min-width="80"></el-table-column>


                <!-- <el-table-column prop="isMp" label="是否是毛坯外协" sortable min-width="100">
                    <template slot-scope="scope">
                        <span v-if="scope.row.isMp ===1" class='el-icon-circle-check  cl-success fn-size18 '></span>
                    </template>
                </el-table-column>
                <el-table-column prop="type" label="不合格类型" sortable min-width="100">
                    <template slot-scope="scope">
                        <span v-html="scope.row.type ===1?'返工':scope.row.type ===2?'报废':'返工+报废'"></span>
                    </template>
                </el-table-column>
                <el-table-column prop="state" label="状态" sortable min-width="100">
                    <template slot-scope="scope">
                        <span v-html="scope.row.state ===0?'待办':'已办'"></span>
                    </template>
                </el-table-column>
                <el-table-column prop="targetType" label="重新生产的类型" sortable min-width="100">
                    <template slot-scope="scope">
                        <span v-html="scope.row.targetType ===1?'内部生产':scope.row.targetType ===2?'毛坯外协':'工序外协'"></span>
                    </template>
                </el-table-column> -->
                <el-table-column label="操作">
                    <template slot-scope="scope">
                    <el-button type="text" @click="showDialog(scope.row)">出库</el-button>
                    </template>
                </el-table-column>
            </el-table>   
            <el-pagination  @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>


    <el-dialog class="bodyNopaddingTop" :title="dialog.title" :visible.sync="dialog.isShow"  v-dialogDrag  width="600px">
          <el-form :inline="true" :model="currentRow" label-width="190px"  class="demo-ruleForm">
              <!-- <el-form-item label="重新生产的类型" >
                  <el-select v-model="currentRow.targetType" clearable>
                      <el-option label="内部生产" :value="1"></el-option>
                      <el-option label="毛坯外协" :value="2"></el-option>
                      <el-option label="工序外协" :value="3"></el-option>
                  </el-select>
              </el-form-item> -->
              <br>
              <el-form-item label="件数" >
                  <el-input-number v-model="currentRow.num" :max="currentRow.nums"></el-input-number>
              </el-form-item>
              <br>
                            <el-form-item label="" >
                            </el-form-item>
           
          </el-form>
          <el-button v-if="activeName==='0'" type="primary" @click="cpkOutSingle" style="float:right;margin-right:30px;margin-bottom:15px;">确定</el-button>

    </el-dialog>
  </div>
</template>
<script>
import planApi from 'plugins/axios/planApi.js';
export default {
    data(){
        return{
            search:{
               drawCode:'', 
               makeNo:'', 
               taskSerialNo:'', 
               code29:'', 
               taskNo:'', 
            },
            ids:'',
            multipleSelection:[],
            currentRow:{},
            tableList:[],
            currentPage:1,
            pageSize:10,
            total:0,
            dialog:{/**弹框配置 */
                title:'',
                isShow:false,
                type:'',
                formData:{},
                activeName:'2',
                otherUpDataData:{},
                tableData:[],
                drawCode:''
            },
            activeName:'0',
        }
    },
    created(){
        this.$nextTick(()=>{
            this.queryTableList();
        });
    },
    methods:{
        tabClick(){
        let self = this;
        self.queryTableList();
        },
        handleSizeChange(){
            let self = this;
        },
        handleCurrentChange(){
            let self = this;
        },
        searchBtn(){
            let self = this;
            self.queryTableList();
        },
        restSearchBtn(){
            let self = this;
            self.search={
               drawCode:'', 
               makeNo:'', 
               taskSerialNo:'', 
               code29:'', 
               taskNo:'', 
            }
            self.queryTableList();
        },
        queryTableList(){
            let self = this;
            let param = {
               currentPage:self.currentPage, 
               pageSize:self.pageSize, 
               drawCode:self.search.drawCode, 
               makeNo:self.search.makeNo, 
               taskSerialNo:self.taskSerialNo, 
               code29:self.search.code29, 
               taskNo:self.search.taskNo, 
            };
            planApi.selectCpk(param).then(res=>{
                self.tableList = res.content.records;
                self.total = res.content.total;
            });
        },
        showDialog(row){
            let self = this;
            self.currentRow = row;
            self.dialog.isShow = true;
        },
        editUnqualified(){
            let self = this;
            let param = {
                id:self.currentRow.id,
                remark:self.currentRow.remark,
                targetType:self.currentRow.targetType,
            }
            planApi.editUnqualified(param).then(res=>{
                self.$message({message:'处理成功',type:'success'});
                self.queryTableList();
            });
        },
        cpkOut(){
            let self = this;
            if(self.ids!=''){
                planApi.cpkOut({totalIds:self.ids}).then(res=>{
                  self.$message({message:'出库成功！',type:'success'});
                  self.queryTableList();

                });
            }else{
                self.$message({message:'请选择出库数据',type:'success'});
            }
        },
        cpkOutSingle(){
            let self = this;
                planApi.cpkOutSingle(self.currentRow.id,self.currentRow.num).then(res=>{
                  self.$message({message:'出库成功！',type:'success'});
                  self.dialog.isShow = false;
                  self.queryTableList();
                });
        
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
            if(val!=null && val.length!=0){
                let idArray = [];
                val.forEach(element => {
                    idArray.push(element.id);
                });
                this.ids =  idArray.join(',');
            }else{
                this.ids='';
            }
        }

    }
}
</script>